TestCase
(
	'org.puremvc.js.patterns.facade.FacadeTest'
	
,	{
		
		testGetInstance: function ()
		{
			var facade= Facade.getInstance()
			
			assertNotNull('The Facade instance was retrieved successfully', facade);
			assertInstanceOf('The returned instance is an instance of Facade', Facade, facade);
		}
		
	,	testRegisterCommandAndSendNotification: function ()
		{
			var facade= Facade.getInstance()
			,	noteName= 'FacadeTestNote'
			,	voValue= 32
			,	vo= new FacadeTestVo(voValue)
			
			facade.registerCommand(noteName, FacadeTestCommand);
			facade.removeCommand(noteName);
			facade.sendNotification(noteName, vo);
			
			// TODO this is an ineffective test- refactor, after all, vo.result could be ANYTHING!
			assertNotSame('Expecting vo result to not equal 64', vo.result, 64);
		}
		
	,	testRegisterAndRemoveCommandAndSendNotification: function ()
		{
   			// Create the Facade, register the FacadeTestCommand to 
   			// handle 'FacadeTest' events
   			var facade = Facade.getInstance();
   			facade.registerCommand('FacadeTestNote',FacadeTestCommand);
   			facade.removeCommand('FacadeTestNote');
   			

			// Send notification. The Command associated with the event
			// (FacadeTestCommand) will NOT be invoked, and will NOT multiply 
			// the vo.input value by 2 
   			var vo = new FacadeTestVo( 32 );
   			facade.sendNotification('FacadeTestNote', vo);
   			
   			// test assertions 
   			assertTrue( "Expecting vo.result != 64", vo.result != 64 );
		}	
		
	,	testRegisterRetrieveAndRemoveMediator: function ()
		{
			var facade= Facade.getInstance()
			,	viewComponent= {}
			,	mediatorName= Mediator.NAME
			,	mediator= new Mediator(mediatorName, viewComponent)
			,	removedMediator
			,	retrievedMediator
			
			
			assertFalse('The facade has not previously registered a mediator with the same name', facade.hasMediator(mediatorName));
			
			facade.registerMediator(mediator);
			assertTrue('The facade has registered the mediator via its View', facade.hasMediator(mediatorName));
			
			retrievedMediator= facade.retrieveMediator(mediatorName);
			assertTrue('The facade retrieved the mediator successfully', null != retrievedMediator);
			assertSame('The retrieved mediator and the mediator object has the same name', mediator.getMediatorName(), retrievedMediator.getMediatorName());
			assertTrue('The mediator was retrieved via #retrieveMediator', mediator === retrievedMediator);
			
			removedMediator= facade.removeMediator(Mediator.NAME);
			assertFalse('The mediator is no longer registered', facade.hasMediator(mediatorName))
			assertSame('The removed mediators name is the same as the name used to remove it'
			,	removedMediator.getMediatorName(), Mediator.NAME);
			assertTrue('The mediator can no longer be retrieved after removal', null == facade.retrieveMediator(Mediator.NAME));

		}
		
	,	testRegisterAndRetrieveProxy: function ()
		{
   			// register a proxy and retrieve it.
   			var facade = Facade.getInstance();
			facade.registerProxy( new Proxy('colors', ['red', 'green', 'blue']) );
			var proxy = facade.retrieveProxy( 'colors' )
			
			// test assertions
   			assertTrue( "Expecting proxy is IProxy", proxy instanceof Proxy);

			// retrieve data from proxy
			var data = proxy.getData();
			
			// test assertions
   			assertNotNull( "Expecting data not null", data );
   			assertTrue( "Expecting data is Array", data instanceof Array );
   			assertTrue( "Expecting data.length == 3", data.length == 3 );
   			assertTrue( "Expecting data[0] == 'red'", data[0]  == 'red' );
   			assertTrue( "Expecting data[1] == 'green'", data[1]  == 'green' );
   			assertTrue( "Expecting data[2] == 'blue'", data[2]  == 'blue' );			
		}
		
	,	testRegisterAndRemoveProxy: function ()
		{
			var facade= Facade.getInstance()
			,	proxyName= 'sizes'
			,	proxyData= ['7', '13', '21']
			,	proxy= new Proxy(proxyName, proxyData)
			,	removedProxy
			,	retrievedProxy
			
			facade.registerProxy(proxy);
			removedProxy= facade.removeProxy(proxyName);
			
			assertSame('The removed proxy was removed by its name', proxyName, removedProxy.getProxyName());
			
			retrievedProxy= facade.retrieveProxy(proxyName);
			
			assertNull('No proxy should be returned, as it has already been removed', retrievedProxy);
		}
		
	,	testRegisterRetrieveAndRemoveMediator: function () 
		{
  			
	   			// register a mediator, remove it, then try to retrieve it
	   			var facade = Facade.getInstance();
				facade.registerMediator( new Mediator( Mediator.NAME, {} ) );
				
				// retrieve the mediator
	   			assertNotNull( "Expecting mediator is not null", facade.retrieveMediator( Mediator.NAME ) );
	
				// remove the mediator
				var removedMediator= facade.removeMediator(Mediator.NAME);
	
				// assert that we have removed the appropriate mediator
	   			assertTrue( "Expecting removedMediator.getMediatorName() == Mediator.NAME", 
							removedMediator.getMediatorName() == Mediator.NAME);
					
				// assert that the mediator is no longer retrievable
	   			assertTrue( "Expecting facade.retrieveMediator( Mediator.NAME ) == null )", facade.retrieveMediator( Mediator.NAME ) == null );
		}
		
	,	testHasProxy: function ()
		{
   			// register a Proxy
			var facade = Facade.getInstance();
			facade.registerProxy( new Proxy( 'hasProxyTest', [1,2,3] ) );
			
   			// assert that the model.hasProxy method returns true
   			// for that proxy name
   			assertTrue( "Expecting facade.hasProxy('hasProxyTest') == true", 
   						facade.hasProxy('hasProxyTest') == true);
		}
		
	,	testHasMediator: function ()
		{
   			// register a Mediator
			var facade = Facade.getInstance();
			facade.registerMediator( new Mediator( 'facadeHasMediatorTest', {} ) );
			
   			// assert that the facade.hasMediator method returns true
   			// for that mediator name
   			assertTrue( "Expecting facade.hasMediator('facadeHasMediatorTest') == true", 
   						facade.hasMediator('facadeHasMediatorTest') == true);
   						
   			facade.removeMediator( 'facadeHasMediatorTest' );
   			
   			// assert that the facade.hasMediator method returns false
   			// for that mediator name
   			assertTrue( "Expecting facade.hasMediator('facadeHasMediatorTest') == false", 
   						facade.hasMediator('facadeHasMediatorTest') == false);
		}
		
	,	testHasCommand: function ()
		{
   			// register the ControllerTestCommand to handle 'hasCommandTest' notes
   			var facade = Facade.getInstance();
   			facade.registerCommand('facadeHasCommandTest', FacadeTestCommand);
   			
   			// test that hasCommand returns true for hasCommandTest notifications 
   			assertTrue( "Expecting facade.hasCommand('facadeHasCommandTest') == true", facade.hasCommand('facadeHasCommandTest') == true );
   			
   			// Remove the Command from the Controller
   			facade.removeCommand('facadeHasCommandTest');
			
   			// test that hasCommand returns false for hasCommandTest notifications 
   			assertTrue( "Expecting facade.hasCommand('facadeHasCommandTest') == false", facade.hasCommand('facadeHasCommandTest') == false );
		}
	}
);
